project(Common)

# gather all source files
file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/includes/*.c?? ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c?? ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c )
file(GLOB_RECURSE headers ${CMAKE_CURRENT_SOURCE_DIR}/includes/*.h)
add_library(${PROJECT_NAME} STATIC ${sources} ${headers})

# export engine symbols
target_compile_definitions(${PROJECT_NAME} PUBLIC 
    -DSHADER_EXPORT
)

# includes directories
target_include_directories(${PROJECT_NAME} PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/includes
    ${CMAKE_CURRENT_SOURCE_DIR}/includes/glad/include
    ${CONAN_INCLUDE_DIRS}
)


# link directories
target_link_directories(${PROJECT_NAME} PUBLIC 
    ${CONAN_LIB_DIRS}  
)

# link libraries
target_link_libraries(${PROJECT_NAME} PUBLIC
    ${CONAN_LIBS}     
)

# copy .dll files
if (MSVC)
    foreach(directory ${CONAN_BIN_DIRS})
        file(GLOB dllfiles ${directory}/*.dll)
        foreach(dllfile ${dllfiles})
            if (EXISTS ${dllfile})
                add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 
                    COMMAND ${CMAKE_COMMAND} -E copy_if_different 
                    ${dllfile} ${EXECUTABLE_OUTPUT_PATH})
            endif()
        endforeach()
    endforeach()
endif(MSVC)

# copy resources
if(EXISTS ${CMAKE_SOURCE_DIR}/Resources)
    add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND 
        ${CMAKE_COMMAND} -E copy_directory 
        ${CMAKE_SOURCE_DIR}/Resources
        ${EXECUTABLE_OUTPUT_PATH}/Resources
    )
else()
    message(WARNING "[WARNING] no resource directory!")
endif()
